package window.component;

import javax.swing.*;
import java.awt.*;

public class ImageSlider extends JPanel {
    public ImageSlider() {
        CardLayout layout = new CardLayout();
        this.setLayout(layout);

        // 添加多个标签或图像
        for (int i = 1; i <= 4; i++) {
            ImageIcon icon = new ImageIcon("res/SliderImage/sliderImage" + i + ".jpg");
            icon.setImage(icon.getImage().getScaledInstance(1200, 300, Image.SCALE_SMOOTH));
            JLabel label = new JLabel(icon);
            this.add(label);
        }

        // 创建计时器，每隔一段时间切换卡片
        Timer timer = new Timer(3000, e -> layout.next(this));
        timer.start();
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("Image Slider");
        ImageSlider slider = new ImageSlider();

        frame.add(slider);
        frame.setSize(400, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
